package com.future.service.Impl;

import com.future.service.EmailService;


import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class EmailServiceImpl implements EmailService {

    @Resource
    private MailProperties mailProperties;

    @Resource
    private JavaMailSender javaMailSender;

    @Override
    public void sendMail(String to, String subject, String content) {

        SimpleMailMessage message = new SimpleMailMessage();
        //设置发送来源
        message.setFrom(mailProperties.getUsername());
        //设置发送的目标
        message.setTo(to);
        //邮件标题
        message.setSubject(subject);
        //邮件内容
        message.setText(content);
        //发送
        javaMailSender.send(message);
    }
}
